/**
 * @param {number[][]} mat
 * @return {number[]}
 */
var findDiagonalOrder = function (mat) {
  let x = 0,
    y = 0;
  let point = { x, y }; //初始点
  //结束的坐标点
  let endx = mat.length - 1;
  let endy = mat[0].length - 1;
  let isGo = true; //是否向上走！准备找到转折点
  let arr = [];
  arr.push(mat[point.x][point.y]);
  while (x != endx || y != endy) {
    console.log(x,y);
    //先上前走一步
    if (isGo) {
      x -= 1;
      y += 1;
    } else {
      y -= 1;
      x += 1;
    }
    console.log(mat[x] ? mat[x][y] : false);
    //判断是否有这个值
    if (mat[x] ? mat[x][y] : false) {
      point.x = x; //更新point这个点
      point.y = y;
      arr.push(mat[point.x][point.y]);
    } else {
      //还得要更新下一个去的点位
      //判断前一个point的点的右边和下边有没有值
      if (isGo == true) {
        //去向的两种去向值判断
        if (mat[point.x]?(mat[point.x][point.y + 1]==0?true:mat[point.x][point.y + 1]):false) {
          x = point.x;
          y = point.y + 1;
        } else {
          x = point.x + 1;
          y = point.y;
        }
      } else {
        if (mat[point.x + 1] ? (mat[point.x + 1][point.y]==0?true:mat[point.x + 1][point.y] ) : false ) {
          x = point.x + 1;
          y = point.y;
        } else {
          x = point.x;
          y = point.y + 1;
        }
      }
      //更新点
      point.x = x;
      point.y = y;
      isGo = !isGo;
      arr.push(mat[x][y]);
    }
  }
  return arr;
};

// mat = [[1,2,3],[4,5,6],[7,8,9]]

// console.log(findDiagonalOrder(mat));



/**
 * 暴力求解法！！！
 * @param {string} s
 * @return {string}
 * 代码优化：
 * 1. 每次遍历到一半就行
 */
var longestPalindrome = function (s) {
  //5  4 4 3 3 3 2 2 2 2 1 1 1 1 1
  let len = s.length//5
  for (let i = len; i > 0; i--) {//层级递减  i=3
      for (let j = 0; j < len - i + 1; j++) {
          let str = s.slice(j, j+i+1) 
          if (isHui(str)) return str
      }
  }
};

function isHui(str) {
  return str.split('').reverse().join('') == str
}

let s =
"kyyrjtdplseovzwjkykrjwhxquwxsfsorjiumvxjhjmgeueafubtonhlerrgsgohfosqssmizcuqryqomsipovhhodpfyudtusjhonlqabhxfahfcjqxyckycstcqwxvicwkjeuboerkmjshfgiglceycmycadpnvoeaurqatesivajoqdilynbcihnidbizwkuaoegmytopzdmvvoewvhebqzskseeubnretjgnmyjwwgcooytfojeuzcuyhsznbcaiqpwcyusyyywqmmvqzvvceylnuwcbxybhqpvjumzomnabrjgcfaabqmiotlfojnyuolostmtacbwmwlqdfkbfikusuqtupdwdrjwqmuudbcvtpieiwteqbeyfyqejglmxofdjksqmzeugwvuniaxdrunyunnqpbnfbgqemvamaxuhjbyzqmhalrprhnindrkbopwbwsjeqrmyqipnqvjqzpjalqyfvaavyhytetllzupxjwozdfpmjhjlrnitnjgapzrakcqahaqetwllaaiadalmxgvpawqpgecojxfvcgxsbrldktufdrogkogbltcezflyctklpqrjymqzyzmtlssnavzcquytcskcnjzzrytsvawkavzboncxlhqfiofuohehaygxidxsofhmhzygklliovnwqbwwiiyarxtoihvjkdrzqsnmhdtdlpckuayhtfyirnhkrhbrwkdymjrjklonyggqnxhfvtkqxoicakzsxmgczpwhpkzcntkcwhkdkxvfnjbvjjoumczjyvdgkfukfuldolqnauvoyhoheoqvpwoisniv"
console.log(longestPalindrome(s));